home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / COLLECTION.PY < prev    next >
Encoding:
Python Source  |  2000-06-09  |  6.7 KB  |  155 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64.  
  65. """WebDAV support - collection objects."""
  66.  
  67. __version__='$Revision: 1.17 $'[11:-2]
  68.  
  69. import sys, os, string, Globals
  70. from common import urlfix, rfc1123_date
  71. from Resource import Resource
  72. from urllib import unquote
  73.  
  74.  
  75. class Collection(Resource):
  76.     """The Collection class provides basic WebDAV support for
  77.     collection objects. It provides default implementations 
  78.     for all supported WebDAV HTTP methods. The behaviors of some
  79.     WebDAV HTTP methods for collections are slightly different
  80.     than those for non-collection resources."""
  81.  
  82.     __dav_collection__=1
  83.  
  84.     def dav__init(self, request, response):
  85.         # We are allowed to accept a url w/o a trailing slash
  86.         # for a collection, but are supposed to provide a
  87.         # hint to the client that it should be using one.
  88.         # [WebDAV, 5.2]
  89.         pathinfo=request.get('PATH_INFO','')
  90.         if pathinfo and pathinfo[-1] != '/':
  91.             location='%s/' % request['URL1']
  92.             response.setHeader('Content-Location', location)
  93.         response.setHeader('Connection', 'close', 1)
  94.         response.setHeader('Date', rfc1123_date(), 1)
  95.         response.setHeader('MS-Author-Via', 'DAV')
  96.  
  97.     def HEAD(self, REQUEST, RESPONSE):
  98.         """Retrieve resource information without a response body."""
  99.         self.dav__init(REQUEST, RESPONSE)
  100.         # Note that we are willing to acquire the default document
  101.         # here because what we really care about is whether doing
  102.         # a GET on this collection / would yield a 200 response.
  103.         if hasattr(self, 'index_html'):
  104.             if hasattr(self.index_html, 'HEAD'):
  105.                 return self.index_html.HEAD(REQUEST, RESPONSE)
  106.             raise 'Method Not Allowed', (
  107.                   'Method not supported for this resource.'
  108.                   )
  109.         raise 'Not Found', 'The requested resource does not exist.'
  110.  
  111.     def PUT(self, REQUEST, RESPONSE):
  112.         """The PUT method has no inherent meaning for collection
  113.         resources, though collections are not specifically forbidden
  114.         to handle PUT requests. The default response to a PUT request
  115.         for collections is 405 (Method Not Allowed)."""
  116.         self.dav__init(REQUEST, RESPONSE)
  117.         raise 'Method Not Allowed', 'Method not supported for collections.'
  118.  
  119.     def DELETE(self, REQUEST, RESPONSE):
  120.         """Delete a collection resource. For collection resources, DELETE
  121.         may return either 200 (OK) or 204 (No Content) to indicate total
  122.         success, or may return 207 (Multistatus) to indicate partial
  123.         success. Note that in Zope a DELETE currently never returns 207."""
  124.         self.dav__init(REQUEST, RESPONSE)
  125.         url=urlfix(REQUEST['URL'], 'DELETE')
  126.         name=unquote(filter(None, string.split(url, '/'))[-1])
  127.         # TODO: add lock checking here
  128.         self.aq_parent._delObject(name)
  129.         RESPONSE.setStatus(204)
  130.         return RESPONSE
  131.  
  132.  
  133. Globals.default__class_init__(Collection)
  134.